package com.yc.consumerservice.controller;

import com.yc.consumerservice.entity.ImagePathEntity;
import com.yc.consumerservice.feign.OcrClient;
import com.yc.consumerservice.util.MinioUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

@RestController
@RequestMapping("/api")
public class OcrController {
    @Autowired
    private OcrClient ocrClient;
    @Autowired
    private MinioUtil minioUtil;

    @GetMapping("/index")
    public String home(){
        return "Hello Aigc!";
    }

    @GetMapping("/recognizeImage")
    public String recognizeImage(@RequestParam String imagefilePath){
        ImagePathEntity imagePathEntity = new ImagePathEntity(imagefilePath);
        ocrClient.recognizeImage(imagePathEntity);
        return "recognizeImage ok";
    }




    @PostMapping(value = "/upload")
    public String uploadReport(MultipartFile imgfile) {
        System.out.println("imgfile:" + imgfile);
        Boolean exitBucketName= minioUtil.existBucket("aigc");
        System.out.println("exitBucketName:"+exitBucketName);
        String fileName = imgfile.getOriginalFilename();
        System.out.println("fileName:" + fileName);
        String rename = UUID.randomUUID().toString();
        System.out.println("rename:" + rename);
        minioUtil.upload(imgfile, fileName);
        return minioUtil.getFileUrl(fileName);
    }


}
